package com.ruoyi.web.customer.service.impl;

import java.util.List;

import com.ruoyi.common.enums.ModuleEnum;
import com.ruoyi.common.utils.sender.NumberSender;
import com.ruoyi.web.customerclass.mapper.CustomerclassMapper;
import com.ruoyi.web.districtclass.mapper.DistrictclassMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.web.customer.mapper.CustomerMapper;
import com.ruoyi.web.customer.domain.Customer;
import com.ruoyi.web.customer.service.ICustomerService;

/**
 * customerService业务层处理
 * 
 * @author ruoyi
 * @date 2024-09-25
 */
@Service
public class CustomerServiceImpl implements ICustomerService 
{
    @Autowired
    private CustomerMapper customerMapper;

    @Autowired
    private CustomerclassMapper customerclassMapper;

    @Autowired
    private DistrictclassMapper districtclassMapper;

    /**
     * 查询customer
     * 
     * @param cCusCode customer主键
     * @return customer
     */
    @Override
    public Customer selectCustomerByCCusCode(String cCusCode)
    {
        return customerMapper.selectCustomerByCCusCode(cCusCode);
    }

    /**
     * 查询customer列表
     * 
     * @param customer customer
     * @return customer
     */
    @Override
    public List<Customer> selectCustomerList(Customer customer)
    {
        return customerMapper.selectCustomerList(customer);
    }

    /**
     * 新增customer
     * 
     * @param customer customer
     * @return 结果
     */
    @Override
    public int insertCustomer(Customer customer)
    {
        return customerMapper.insertCustomer(customer);
    }

    /**
     * 修改customer
     * 
     * @param customer customer
     * @return 结果
     */
    @Override
    public int updateCustomer(Customer customer)
    {
        if (customer.getCountry()!=null&&!customer.getCountry().matches("\\d+")){
            String country = districtclassMapper.selectDistrictclassByCDCName(customer.getCountry()).getcDCCode();
            customer.setCountry(country);
        }
        if (customer.getProvince()!=null&&!customer.getProvince().matches("\\d+")){
            String province = districtclassMapper.selectDistrictclassByCDCName(customer.getProvince()).getcDCCode();
            customer.setProvince(province);
        }
        if (customer.getcDCCode()!=null&&!customer.getcDCCode().matches("\\d+")){
            String cDCCode = districtclassMapper.selectDistrictclassByCDCName(customer.getcDCCode()).getcDCCode();
            customer.setcDCCode(cDCCode);
        }

        if (customer.getcCCCode()!=null&&!customer.getcCCCode().matches("\\d+")){
            String cVCCode = customerclassMapper.selectCustomerclassByCCCName(customer.getcCCCode()).getcCCCode();
            customer.setcCCCode(cVCCode);
        }
        return customerMapper.updateCustomer(customer);
    }



    /**
     * 批量删除customer
     * 
     * @param cCusCodes 需要删除的customer主键
     * @return 结果
     */
    @Override
    public int deleteCustomerByCCusCodes(String[] cCusCodes)
    {
        return customerMapper.deleteCustomerByCCusCodes(cCusCodes);
    }

    /**
     * 删除customer信息
     * 
     * @param cCusCode customer主键
     * @return 结果
     */
    @Override
    public int deleteCustomerByCCusCode(String cCusCode)
    {
        return customerMapper.deleteCustomerByCCusCode(cCusCode);
    }
}
